﻿using System;
using Core;
using NUnit.Framework;

namespace Tests
{
    [TestFixture]
    public class WordFinderTests
    {
        [Test]
        public void Should_find_AT_and_AN()
        {
            var board = new Board(3,
                                  Tiles.A, Tiles.T, Tiles.X,
                                          Tiles.N, Tiles.X,
                                  Tiles.X, Tiles.X, Tiles.X);

            var wl = new Wordlist("AN", "AT");

            var finder = new SimpleWordFinder(board, wl);
            finder.OnWordFound += (moves => Console.WriteLine("Word found: [" + board.MovesToWord(moves) + "]"));
            finder.FindAllWords();
        }

        [Test]
        public void Should_find_AT_and_AN_and_ANT()
        {
            var board = new Board(3,
                                  Tiles.A, Tiles.T, Tiles.X,
                                          Tiles.N, Tiles.X,
                                  Tiles.X, Tiles.X, Tiles.X);

            var wl = new Wordlist("AN", "AT","ANT");

            var finder = new SimpleWordFinder(board, wl);
            finder.OnWordFound += (moves => Console.WriteLine("Word found: [" + board.MovesToWord(moves) + "]"));
            finder.FindAllWords();
        }

        [Test]
        public void Should_find_AT_and_ATE()
        {
            var board = new Board(3,
                                  Tiles.A, Tiles.T, Tiles.E,
                                          Tiles.X, Tiles.X,
                                  Tiles.X, Tiles.X, Tiles.X);

            var wl = new Wordlist("AT", "ATE");

            var finder = new SimpleWordFinder(board, wl);
            finder.OnWordFound += (moves => Console.WriteLine("Word found: [" + board.MovesToWord(moves) + "]"));
            finder.FindAllWords();
        }

        [Test]
        public void Should_find_DOG_and_GOD()
        {
            var board = new Board(3,
                                  Tiles.D, Tiles.O, Tiles.G,
                                          Tiles.X, Tiles.X,
                                  Tiles.X, Tiles.X, Tiles.X);

            var wl = new Wordlist("DOG", "GOD");

            var finder = new SimpleWordFinder(board, wl);
            finder.OnWordFound += (moves => Console.WriteLine("Word found: [" + board.MovesToWord(moves) + "]"));
            finder.FindAllWords();
        }

        [Test]
        public void Should_find_Words()
        {
            var size = 9;

            var board = new Board(size, (((2 * size) - 1) * 3) + size);

            var wl = new Wordlist("DOG", "GOD", "DO");

            var finder = new SimpleWordFinder(board, wl);
            finder.OnWordFound += (moves => Console.WriteLine("Word found: [" + board.MovesToWord(moves) + "]"));
            finder.FindAllWords();
        }

    }
}
